﻿using System;
using System.Collections.Generic;

namespace MoqExamples
{
    public class SampleClass
    {
        private string _nonVirtualProperty;
        public string NonVirtualProperty
        {
            get { return _nonVirtualProperty; }
            set
            {
                _nonVirtualProperty = value;
                NonVirtualPropertyWasSet = true;
            }
        }

        private string _virtualProperty;
        public virtual string VirtualProperty
        {
            get { return _virtualProperty; }
            set
            {
                _virtualProperty = value;
                VirtualPropertyWasSet = true;
            }
        }

        public string SetByConstructor { get; private set; }
        public bool NonVirtualPropertyWasSet { get; set; }
        public bool VirtualPropertyWasSet { get; set; }
        public bool VoidMethodWasCalled { get; set; }
        public bool VirtualMethodWasCalled { get; set; }
        public bool NonVirtualMethodWasCalled { get; set; }

        public event EventHandler SomeEvent;
        public virtual event EventHandler SomeVirtualEvent;
        public event EventHandler NonVirtualEvent;

        public SampleClass()
        {

        }

        public SampleClass(string value)
        {
            SetByConstructor = value;
        }

        public void VoidMethod()
        {
            VoidMethodWasCalled = true;
        }

        public virtual int VirtualMethod(string s)
        {
            VirtualMethodWasCalled = true;
            return s.Length;
        }

        public IList<int> NonVirtualMethod(int i)
        {
            NonVirtualMethodWasCalled = true;
            return new List<int> { i };
        }

        public void FireSomeVirtualEvent()
        {
            if (SomeVirtualEvent != null)
                SomeVirtualEvent(this, EventArgs.Empty);
        }

        public void FireNonVirtualEvent()
        {
            if (NonVirtualEvent != null)
                NonVirtualEvent(this, EventArgs.Empty);
        }

        public int CallSomeProtectedMethod()
        {
            return SomeProtectedMethod();
        }

        public int CallProtectedMethodWithParameter(string argumentForMethod)
        {
            return ProtectedMethodWithParameter(argumentForMethod);
        }

        public virtual void VirtualMethodThatCallsAnotherVirtual()
        {
            AnotherVirtualMethod();
        }

        public virtual void AnotherVirtualMethod()
        {
            //do nothing
        }

        protected virtual int SomeProtectedMethod()
        {
            return 50;
        }

        protected virtual int ProtectedMethodWithParameter(string foo)
        {
            return foo.Length;
        }
    }
}